package com.marvels.product.common.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.Page;
import com.marvels.common.dto.PageInfoDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.product.param.api.ProductChannelApi;
import com.marvels.product.param.api.ProductConsultFeeApi;
import com.marvels.product.param.api.ProductTypeApi;
import com.marvels.product.param.dto.CascadeChannelDto;
import com.marvels.product.param.dto.McptConsultingFeeDTO;
import com.marvels.product.param.dto.McptManagementFeeDTO;
import com.marvels.product.param.dto.McptProduct;
import com.marvels.product.param.dto.McptProductType;
import com.marvels.product.param.dto.McptRateDTO;
import com.marvels.product.param.dto.McptRiskFeeDTO;
import com.marvels.product.param.service.ProductItemService;
import com.marvels.product.productmanage.dto.McptChannelDto;
import com.marvels.product.productmanage.dto.McptProductFundRelationDto;
import com.marvels.product.productmanage.dto.McptProductInfoDTO;
import com.marvels.product.productmanage.dto.McptProductMappedDto;
import com.marvels.product.productmanage.dto.McptProductTypeDto;

@RestController
@RequestMapping("/product/api")
public class ProductProvideController {
	
	@Autowired
	private ProductChannelApi productChannelApi;
	
	@Autowired
	private ProductItemService productItemService;
	
	@Autowired
	private ProductTypeApi productTypeApi;
	
	@Autowired
	private ProductConsultFeeApi productConsultFeeApi;
	
	/**
	 * 查询渠道信息
	 * @param data
	 * @return
	 */
	@RequestMapping("/mcptChannelInfo")
	@ResponseBody
    public CascadeChannelDto mcptChannelInfo(@RequestBody McptChannelDto mcptChannelDto) {
        return productChannelApi.mcptChannelInfo(mcptChannelDto);
    }
	
	
	
	
	/**
	 * 查询渠道信息
	 * @param data
	 * @return
	 */
	@RequestMapping("/mcptChannelAllInfo")
	@ResponseBody
    public List<McptChannelDto> mcptChannelAllInfo(@RequestBody McptChannelDto mcptChannelDto) {
        return productChannelApi.mcptChannelAllInfo(mcptChannelDto);
    }
	
	
	
	/**
	 * 查询产品信息
	 * @param data
	 * @return
	 */
	@RequestMapping("/mcptProductTypeInfo")
	@ResponseBody
    public List<McptProductType> mcptProductTypeInfo(@RequestBody McptProductType productType) {
        return productTypeApi.mcptProductTypeInfo(productType);
    }
	
	
	/**
	 * 分页查询产品信息
	 * @param data
	 * @return
	 */
	@RequestMapping("/productTypePageInfo")
	@ResponseBody
    public PageInfoDTO<McptProductType> productTypePageInfo(@RequestBody McptProductType productType) {
		Page<McptProductType> list=productTypeApi.productTypePageInfo(productType);
		PageInfoDTO<McptProductType> listData=new PageInfoDTO<McptProductType>();
		listData.setTotal(list.getTotal());
		listData.setList(list.getResult());
        return listData;
    }
	
	/**
	 * 根据产品小类code查询咨询费信息
	 * @param data
	 * @return
	 */
	@RequestMapping("/mcptConsultFee")
	@ResponseBody
    public McptConsultingFeeDTO mcptConsultFee(@RequestParam(value="productCode") String productCode) {
        return productConsultFeeApi.selectByProductCode(productCode);
    }
	
	/***
	 * 根据条件查询产品信息
	 * @param productCode
	 * @return
	 * @throws MarvelsBusinessException 
	 */
	@RequestMapping("/getEntityByPrimaryKey")
	@ResponseBody
    public McptRiskFeeDTO getEntityByPrimaryKey(@RequestParam(value="riskFeeId") Long riskFeeId) throws MarvelsBusinessException {
		return productConsultFeeApi.getEntityByPrimaryKey(riskFeeId);
    }
	
	/**
	 * 查询最低金额
	 * @param mcptProducTypeDto
	 * @return
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("/getProductType")
	@ResponseBody
	public McptProductTypeDto getProductType(@RequestParam(value="ProductCode") String ProductCode) throws MarvelsBusinessException {
		McptProductTypeDto list= productConsultFeeApi.getProductType(Long.getLong(ProductCode));
		return list;
	}
	
	/**
	 * 查询贷款产品
	 * @param mcptProducTypeDto
	 * @return
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("/getProduct")
	@ResponseBody
	public McptProduct getProduct(@RequestParam(value="ProductCode") String ProductCode) throws MarvelsBusinessException {
		McptProduct dto = new McptProduct();
		dto.setProductCode(ProductCode);
		McptProduct list= productConsultFeeApi.getProduct(dto);
		return list;
	}
	
	/**
	 * 
	 * @param mcptProducTypeDto
	 * @return
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("/getMngfee")
	@ResponseBody
	public McptManagementFeeDTO getMngfee(@RequestParam(value="managementFeeId") Long managementFeeId) throws MarvelsBusinessException {
		return productConsultFeeApi.getMngfee(managementFeeId);
	}
	
	/***
	 * 
	 * @param consultingFeeId
	 * @return
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("/getConsultingFee")
	@ResponseBody
	public McptConsultingFeeDTO getConsultingFee(@RequestParam(value="consultingFeeId") Long consultingFeeId) throws MarvelsBusinessException {
		return productConsultFeeApi.getConsultingFee(consultingFeeId);
	}
	
	/**
	 * 
	 * @param rateId
	 * @return
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("/getInterestRate")
	@ResponseBody
	public McptRateDTO getInterestRate(@RequestParam(value="rateId")  Long rateId) throws MarvelsBusinessException {
		return productConsultFeeApi.getInterestRate(rateId);
	}
	
	/**
	 * 
	 * @param mcpdto
	 * @return
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("/getProductFundingSource")
	@ResponseBody
	public List<McptProductFundRelationDto> getProductFundingSource(@RequestBody McptProductFundRelationDto mcpdto) throws MarvelsBusinessException {
		return productConsultFeeApi.getProductFundingSource(mcpdto);
	}
	
	
	
	/**
	 * 查询产品映射信息
	 * @param mcpdto
	 * @return
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("/selectProductMappedInfo")
	@ResponseBody
	public List<McptProductMappedDto> selectProductMappedInfo(@RequestBody McptProductMappedDto mcpdto) throws MarvelsBusinessException {
		return productItemService.selectProductMappedInfo(mcpdto);
	}
	
	
	/**
	 * 查询产品类别信息
	 * @param mcpdto
	 * @return
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("/selectProductInfo")
	@ResponseBody
	public List<McptProductInfoDTO> selectProductInfo(@RequestBody McptProductInfoDTO mcpdto) throws MarvelsBusinessException {
		return productItemService.selectProductInfo(mcpdto);
	}
}